package com.testword.mappers;

import com.testword.entity.WordDifficulty;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface DifficultyMapper {
    @Select("SELECT id, difficulties FROM wordtable ORDER BY difficulties ASC")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "difficulties", property = "difficulties", jdbcType = JdbcType.DOUBLE)
    })
    List<WordDifficulty> getAllDifficulties();


    @Select("SELECT body FROM wordtable")
    List<String> getWords();

    /**
     * @param word
     * @return
     */
    @Select("SELECT frequency FROM wordtable WHERE body=#{word} ")
    Integer getFrequency(String word);

    @Update("UPDATE wordtable SET difficulties = #{difficulty} WHERE body = #{word}")
    void updateDifficulty(String word, double difficulty);
}
